package com.guigu.hkw.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class ExceptionMapp implements HandlerExceptionResolver {
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ex.printStackTrace();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/error");
        //判断异常是否是权限异常
        if (ex instanceof UnauthorizedException){
            modelAndView.setViewName("/error");
        }else {
            modelAndView.setViewName("/systemError");
        }
        return modelAndView;
    }
}
